package cn.cmcc.online.smsapi.sdk.util;

import cn.cmcc.online.smsapi.sdk.constant.Constant;
import cn.cmcc.online.smsapi.sdk.db.entity.SysParamEntityManager;
import cn.cmcc.online.smsapi.sdk.net.NewXyHttpRunnable;
import cn.cmcc.online.smsapi.sdk.net.XyHttpRunnable;

public class KeyManager {

	public static String channel =null;
	
	/*SDK-732 songzhirong 20170314 start*/
	public static void initAppKey(String initChannel,String appkey)throws Exception{
		  channel = initChannel;
		  if(StringUtils.isNull(channel)){
              channel= SysParamEntityManager.getStringParam(Constant.getContext(), Constant.CHANNEL);
		  }	
		  if(!StringUtils.isNull(appkey)){
			  XyHttpRunnable.appKey = appkey;
		  }
		  if(StringUtils.isNull(XyHttpRunnable.appKey)){
			  XyHttpRunnable.appKey= SysParamEntityManager.getStringParam(Constant.getContext(), Constant.CONFIG_APPKEY);
		  }
		 
		  XyHttpRunnable.appKeySign=SysParamEntityManager.getStringParam(Constant.getContext(),Constant.SECRETKEY);
		  NewXyHttpRunnable.RSA_PRV_KEY = SysParamEntityManager.getStringParam(Constant.getContext(),Constant.RSAPRVKEY);
			
		  if(StringUtils.isNull(XyHttpRunnable.appKey)){
			  throw new Exception("无效的渠道");
		  }
	}
	/*SDK-732 songzhirong 20170314 start*/
	public static void initAppKey()throws Exception{
		initAppKey("","");
	}
	/*SDK-732 songzhirong 20170314 end*/

	public static String getAppKey(){
		return XyHttpRunnable.appKey;
	}
}
